Merged all missions in to one single mission page

jamesperet 11 years ago
parent
commit
83bf8021fb

+ 0 - 9
app/controllers/agent_controller.rb

@@ -1,15 +1,6 @@
1 1
 class AgentController < ApplicationController
2 2
   
3 3
   layout 'front_end'
4
-  
5
-  def current_missions
6
-    
7
-  end
8
-
9
-  def choose_mission
10
-    @user = User.find(current_user.id)
11
-    @mission_invites = @user.mission_agent_invites.where(:status => 'invited')
12
-  end
13 4
 
14 5
   def agent_profile
15 6
       @user = User.find(params[:id])

+ 45 - 1
app/controllers/missions_controller.rb

@@ -10,7 +10,9 @@ class MissionsController < ApplicationController
10 10
   def index
11 11
     @user = User.find(current_user.id)
12 12
     @missions = @user.mission_agent_invites.where(:status => 'accepted')
13
+    @missions += @user.mission_agent_invites.where(:status => 'Completed')
13 14
     @mission_control = Mission.where(:owner => @user)
15
+    @mission_invites = @user.mission_agent_invites.where(:status => 'invited')
14 16
   end
15 17
   
16 18
   def list
@@ -72,8 +74,18 @@ class MissionsController < ApplicationController
72 74
               @step.description = s[:description]
73 75
               @step.save
74 76
             end
77
+            # Update Step Order
78
+            @steps = MissionAgentStep.order(:step => :asc).find_all_by_mission_agent_id(@step.mission_agent)
79
+            @step_number = 1
80
+            @steps.each do |step|
81
+              step.step = @step_number
82
+              step.save
83
+              @step_number = @step_number + 1
84
+            end
75 85
           end
76 86
         end
87
+        
88
+        
77 89
 
78 90
         format.html { redirect_to mission_control_path(@mission), notice: 'Mission was successfully updated.' }
79 91
         format.json { head :no_content }
@@ -136,12 +148,44 @@ class MissionsController < ApplicationController
136 148
   def validate_agent_step
137 149
     @step = MissionAgentStep.find(params[:mission_agent_step][:id])
138 150
     @step.proof = params[:mission_agent_step][:proof]
139
-    @step.completed = true
151
+    @step.status = 'Waiting Validation'
140 152
     @mission = @step.mission_agent.mission
141 153
     if @step.save
142 154
       redirect_to mission_path(@mission), notice: 'Step completed!'
143 155
     end
144 156
   end
157
+  
158
+  def mission_agent_step_validate_check
159
+    @step = MissionAgentStep.find(params[:id])
160
+    @step.validated = true
161
+    @step.validated_by = current_user
162
+    @step.completed = true
163
+    @step.status = 'Completed'
164
+    @step.save
165
+    @mission_completed = true
166
+    @step.mission_agent.mission_agent_steps.each do |s|
167
+      if s.completed == false
168
+        @mission_completed = false
169
+      end
170
+    end
171
+    if @mission_completed == true
172
+      @step.mission_agent.mission_agent_invites.where(:user => @step.mission_agent.user).last.update(:status => "Completed")
173
+    end
174
+    @mission = @step.mission_agent.mission
175
+    redirect_to mission_control_path(@mission), notice: 'Step Validated!'
176
+  end
177
+  
178
+  def mission_agent_step_invalidate_check
179
+    @step = MissionAgentStep.find(params[:id])
180
+    @step.validated = false
181
+    @step.validated_by = current_user
182
+    @step.completed = false
183
+    @step.status = 'Incomplete'
184
+    @mission = @step.mission_agent.mission
185
+    if @step.save
186
+      redirect_to mission_control_path(@mission), notice: 'Step Invalidated!'
187
+    end
188
+  end
145 189
 
146 190
   private
147 191
     # Use callbacks to share common setup or constraints between actions.

+ 1 - 0
app/models/mission_agent_step.rb

@@ -1,3 +1,4 @@
1 1
 class MissionAgentStep < ActiveRecord::Base
2 2
   belongs_to :mission_agent
3
+  belongs_to :validated_by, :class_name => "User"
3 4
 end

+ 1 - 0
app/models/user.rb

@@ -6,4 +6,5 @@ class User < ActiveRecord::Base
6 6
          
7 7
   has_many :mission_agent_invites
8 8
   has_many :missions
9
+  has_many :validated_bys
9 10
 end

+ 0 - 22
app/views/agent/choose_mission.html.erb

@@ -1,22 +0,0 @@
1
-<div class="page-header">
2
-  <h1>Choose your Missions </h1>
3
-</div>
4
-<ul class="thumbnails">
5
-<% @mission_invites.each do |invite| %>
6
-	<li class="span4">
7
-		    <div class="thumbnail" style= "padding: 5px;">
8
-		      <h3 style= "padding: 5px;"><%= invite.mission_agent.mission.title %></h3>
9
-		      <p style= "padding: 5px; height: 50px;"><%= invite.mission_agent.mission.description %></p>
10
-			 <div style="width: 48%; float: left;">
11
-				 <%= link_to 'accept', mission_agent_accept_path(invite.id), :class => "btn btn-large btn-block btn-success" %>
12
-			 </div>
13
-			 <div style="width: 48%; float: right;">
14
-			 	<%= link_to 'Denie', mission_agent_denie_path(invite.id), :class => "btn btn-large btn-block btn-danger" %>
15
-			 </div>
16
-			 <div class="clearfix"></div>
17
-		    </div>
18
-		  
19
-		
20
-	</li>
21
-<% end %>
22
-</ul>

+ 2 - 2
app/views/layouts/partials/_nav_links.html.erb

@@ -1,7 +1,6 @@
1 1
 <ul class="nav">
2 2
    <% if user_signed_in? %>
3 3
    	<li><%= link_to "Missions", missions_path  %></li>
4
-	<li><%= link_to "Choose Missions", mission_choose_path  %></li>
5 4
    <% else %>
6 5
    	<li><%= link_to "About", start_about_path  %></li>
7 6
    	
@@ -19,7 +18,8 @@
19 18
 				<% end %>
20 19
 			</a>
21 20
 		    	<ul class="dropdown-menu">
22
-	  			<li><%= link_to 'Edit profile', edit_user_registration_path %></li>
21
+				<li><%= link_to 'Agent Profile', agent_profile_path(current_user) %></li>
22
+	  			<li><%= link_to 'Edit Account', edit_user_registration_path %></li>
23 23
 	  			<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
24 24
 			</ul>
25 25
 		</li>

+ 1 - 1
app/views/missions/_mission_agent_form.html.erb

@@ -5,7 +5,7 @@
5 5
 	<%= f.text_area :description%><br/>
6 6
 	<%= f.hidden_field :_destroy%>
7 7
 	<%= link_to "remove", '#', class: "remove_fields"%>
8
-	<%= f.fields_for :mission_agent_steps do |step_builder| %>
8
+	<%= f.fields_for :mission_agent_steps, MissionAgentStep.where(:mission_agent_id => f.object.id).order(:step => :asc) do |step_builder| %>
9 9
 		<%= render 'mission_agent_step_form', f: step_builder %>
10 10
 	<%end%>
11 11
 	<% @agent = @agent + 1 %>

+ 15 - 0
app/views/missions/_mission_agent_step_status.html.erb

@@ -0,0 +1,15 @@
1
+<% case step.status %>
2
+<% when 'Completed' %>
3
+  <% @step_text = 'Completed' %>
4
+  <% @step_label = 'label-success' %>
5
+<% when 'Waiting Validation' %>
6
+  <% @step_text = 'Waiting Validation' %>
7
+  <% @step_label = 'label-warning' %>
8
+<% else %>
9
+  <% @step_text = 'Incomplete' %>
10
+  <% @step_label = 'label-default' %>
11
+<% end %>
12
+
13
+<span class="label <%= @step_label %> pull-right" style="margin-top: 10px; margin-right: 5px;">
14
+	<%= @step_text %>
15
+</span>

+ 52 - 24
app/views/missions/index.html.erb

@@ -1,26 +1,54 @@
1
-<div class="page-header">
2
-  <h1>Assigned Missions</h1>
3
-</div>
4
-<ul class="thumbnails">
5
-<% @missions.each do |invite| %>
6
-	<li class="span4">
7
-	    <div class="thumbnail" style= "padding: 5px;">
8
-		      <h3 style= "padding: 5px;"><%= link_to invite.mission_agent.mission.title, mission_path(invite.mission_agent.mission) %></h3>
1
+<% if @mission_invites.length > 0 %>
2
+	<div class="page-header">
3
+	  <h1>Choose your Missions </h1>
4
+	</div>
5
+	<ul class="thumbnails">
6
+	<% @mission_invites.each do |invite| %>
7
+		<li class="span4">
8
+		    <div class="thumbnail" style= "padding: 5px;">
9
+		      <h3 style= "padding: 5px;"><%= invite.mission_agent.mission.title %></h3>
9 10
 		      <p style= "padding: 5px; height: 50px;"><%= invite.mission_agent.mission.description %></p>
10
-	    </div>
11
-	</li>
11
+			 <div style="width: 48%; float: left;">
12
+				 <%= link_to 'accept', mission_agent_accept_path(invite.id), :class => "btn btn-large btn-block btn-success" %>
13
+			 </div>
14
+			 <div style="width: 48%; float: right;">
15
+			 	<%= link_to 'Denie', mission_agent_denie_path(invite.id), :class => "btn btn-large btn-block btn-danger" %>
16
+			 </div>
17
+			 <div class="clearfix"></div>
18
+		    </div>
19
+		</li>
20
+	<% end %>
21
+	</ul>
12 22
 <% end %>
13
-</ul>
14
-<div class="page-header">
15
-  <h1>Missions Control</h1>
16
-</div>
17
-<ul class="thumbnails">
18
-<% @mission_control.each do |mission| %>
19
-	<li class="span4">
20
-	    <div class="thumbnail" style= "padding: 5px;">
21
-		      <h3 style= "padding: 5px;"><%= link_to mission.title, mission_control_path(mission) %></h3>
22
-		      <p style= "padding: 5px; height: 50px;"><%= mission.description %></p>
23
-	    </div>
24
-	</li>
25
-<% end %>
26
-</ul>
23
+
24
+<% if @missions.length > 0%>
25
+	<div class="page-header">
26
+	  <h1>Assigned Missions</h1>
27
+	</div>
28
+	<ul class="thumbnails">
29
+	<% @missions.each do |invite| %>
30
+		<li class="span4">
31
+		    <div class="thumbnail" style= "padding: 5px;">
32
+			      <h3 style= "padding: 5px;"><%= link_to invite.mission_agent.mission.title, mission_path(invite.mission_agent.mission) %></h3>
33
+			      <p style= "padding: 5px; height: 50px;"><%= invite.mission_agent.mission.description %></p>
34
+		    </div>
35
+		</li>
36
+	<% end %>
37
+	</ul>
38
+<% end %>	
39
+
40
+<% if @mission_control.length > 0 %>
41
+	<div class="page-header">
42
+	  <h1>Missions Control</h1>
43
+	</div>
44
+	<ul class="thumbnails">
45
+	<% @mission_control.each do |mission| %>
46
+		<li class="span4">
47
+		    <div class="thumbnail" style= "padding: 5px;">
48
+			      <h3 style= "padding: 5px;"><%= link_to mission.title, mission_control_path(mission) %></h3>
49
+			      <p style= "padding: 5px; height: 50px;"><%= mission.description %></p>
50
+		    </div>
51
+		</li>
52
+	<% end %>
53
+	</ul>
54
+<% end%>

+ 15 - 3
app/views/missions/mission_control.html.erb

@@ -28,6 +28,9 @@
28 28
 				<% @status_label = 'label-success'%>
29 29
 			<% elsif agent.mission_agent_invites.last.status == 'denied' %>
30 30
 				<% @status_label = 'label-important'%>
31
+			<% elsif agent.mission_agent_invites.last.status == 'Completed' %>
32
+				<% @status_label = 'label-success'%>
33
+				<% @agent_status = 'closed'%>
31 34
 			<% else%>
32 35
 				<% @status_label = 'label-default'%>
33 36
 			<% end %>
@@ -64,16 +67,25 @@
64 67
 		    </span>
65 68
 		    <div class="clearfix"></div>
66 69
 	       </div>
67
-	       <div id="collapse_<%= agent.id %>" class="accordion-body collapse <% if @agent_status == 'missing' || @agent_status == 'empty' %> out <% else %> in <% end %>">
70
+	       <div id="collapse_<%= agent.id %>" class="accordion-body collapse <% if @agent_status == 'missing' || @agent_status == 'empty' ||  @agent_status == 'closed' %> out <% else %> in <% end %>">
68 71
 	         <div class="accordion-inner">
69 72
 			<div class="row-fluid">
70 73
 				<ul class="thumbnails">
71 74
 					<% @step = 1 %>
72
-					<% agent.mission_agent_steps.each do |step| %>
75
+					<% agent.mission_agent_steps.order(:step => :asc).each do |step| %>
73 76
 						<li class="span4">
74 77
 						    <div class="thumbnail" style= "padding: 5px;">
75
-							<h3 style= "padding: 5px;">Step <%= @step %></h3>
78
+							<h3 style= "padding: 5px; margin-top: 0px;">Step <%= @step %> <%= render 'mission_agent_step_status', :step => step %></h3>
76 79
 							 <p style= "padding: 5px; height: 50px;"><%= step.description %></p>
80
+							 <% if step.status == 'Waiting Validation'%>
81
+								 <div class="well well-small" style="margin-bottom: 0px; text-align: center; height: 90px;">
82
+									 <p style="height: 60px"><strong>Response:</strong> <%= step.proof %></p>
83
+									 <div style=" margin-top: 10px">
84
+									 <%= link_to 'Invalidade', step_invalidate_check_path(step.id), :class => 'btn btn-danger btn-mini' %> 
85
+									 <%= link_to 'Validade', step_validate_check_path(step.id), :class => 'btn btn-success btn-mini', :style => 'margin-right: 5px;' %>
86
+								 </div>
87
+								 </div>
88
+							<% end %>
77 89
 						</li>
78 90
 						<% @step = @step + 1 %>
79 91
 					<% end %>

+ 6 - 4
app/views/missions/show.html.erb

@@ -16,12 +16,14 @@
16 16
 <ul class="thumbnails">
17 17
 <% @step = 1 %>
18 18
 <% if @agent.length > 0 %>
19
-	<% @agent.first.mission_agent_steps.each do |step| %>
19
+	<% @agent.first.mission_agent_steps.order(:step => :asc).each do |step| %>
20 20
 		<li class="span4">
21 21
 		    <div class="thumbnail" style= "padding: 5px;">
22
-			<h3 style= "padding: 5px;">Step <%= @step %></h3>
22
+			<h3 style= "padding: 5px;">Step <%= @step %> <%= render 'mission_agent_step_status', :step => step %></h3>
23 23
 			 <p style= "padding: 5px; height: 50px;"><%= step.description %></p>
24
-			 <a href="#myModal<%= @step %>" role="button" class="btn btn-block btn-default" data-toggle="modal">Validate</a>
24
+			 <% if step.validated != true || step.completed != true %>
25
+			 	<a href="#myModal<%= @step %>" role="button" class="btn btn-block btn-default" data-toggle="modal">Validate</a>
26
+			<% end %>
25 27
 		</li>
26 28
 		<% @step = @step + 1 %>
27 29
 	<% end %>
@@ -29,7 +31,7 @@
29 31
 </ul>
30 32
 
31 33
 <% @step = 1 %>
32
-<% @agent.first.mission_agent_steps.each do |step| %>
34
+<% @agent.first.mission_agent_steps.order(:step => :asc).each do |step| %>
33 35
 
34 36
 <!-- Modal -->
35 37
 <div id="myModal<%= @step %>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

+ 2 - 1
config/routes.rb

@@ -1,7 +1,6 @@
1 1
 AvalancheGame::Application.routes.draw do
2 2
   get "start/about"
3 3
   get "agent/current_missions"
4
-  get "choose_missions" => "agent#choose_mission", :as => :mission_choose
5 4
   get "accept_mission/:id" => "agent#accept_mission", :as => :mission_agent_accept
6 5
   get "denie_mission/:id" => "agent#denie_mission", :as => :mission_agent_denie
7 6
   get "agent/:id" => "agent#agent_profile", :as => :agent_profile
@@ -11,6 +10,8 @@ AvalancheGame::Application.routes.draw do
11 10
   get "mission_control/:id" => "missions#mission_control", :as => :mission_control
12 11
   get "mission_list" => "missions#list", :as => :mission_list
13 12
   patch "mission_agent_step" => "missions#validate_agent_step", :as => :mission_agent_step
13
+  get "mission_agent_step_validate_check/:id" => "missions#mission_agent_step_validate_check", :as => :step_validate_check
14
+  get "mission_agent_step_invalidate_check/:id" => "missions#mission_agent_step_invalidate_check", :as => :step_invalidate_check
14 15
   resources :missions
15 16
   
16 17
   devise_for :users, :skip => [:sessions, :passwords, :confirmations, :registrations]

+ 7 - 0
db/migrate/20140829041611_add_validation_to_mission_agent_step.rb

@@ -0,0 +1,7 @@
1
+class AddValidationToMissionAgentStep < ActiveRecord::Migration
2
+  def change
3
+    add_column :mission_agent_steps, :status, :string
4
+    add_column :mission_agent_steps, :validated, :boolean
5
+    add_reference :mission_agent_steps, :validated_by, index: true
6
+  end
7
+end

+ 5 - 1
db/schema.rb

@@ -11,7 +11,7 @@
11 11
 #
12 12
 # It's strongly recommended that you check this file into your version control system.
13 13
 
14
-ActiveRecord::Schema.define(version: 20140825202313) do
14
+ActiveRecord::Schema.define(version: 20140829041611) do
15 15
 
16 16
   # These are extensions that must be enabled in order to support this database
17 17
   enable_extension "plpgsql"
@@ -46,9 +46,13 @@ ActiveRecord::Schema.define(version: 20140825202313) do
46 46
     t.string   "proof"
47 47
     t.datetime "created_at"
48 48
     t.datetime "updated_at"
49
+    t.string   "status"
50
+    t.boolean  "validated"
51
+    t.integer  "validated_by_id"
49 52
   end
50 53
 
51 54
   add_index "mission_agent_steps", ["mission_agent_id"], name: "index_mission_agent_steps_on_mission_agent_id", using: :btree
55
+  add_index "mission_agent_steps", ["validated_by_id"], name: "index_mission_agent_steps_on_validated_by_id", using: :btree
52 56
 
53 57
   create_table "mission_agents", force: true do |t|
54 58
     t.integer  "mission_id"